package com.yunfeng.aolin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yunfeng.aolin.dao.EmbossedDAO;
import com.yunfeng.aolin.entity.Embossed;
import com.yunfeng.aolin.service.EmbossedService;
import com.yunfeng.common.util.Page;
import com.yunfeng.common.util.PageUtils;

@Service
@Transactional
public class EmbossedServiceImpl implements EmbossedService {

	@Autowired
	private EmbossedDAO embossedDAO;

	/**
	 * @param id
	 * @return
	 * @see com.yunfeng.aolin.service.EmbossedService#get(java.lang.Long)
	 */
	@Override
	public Embossed get(Long id) {
		return embossedDAO.findOne(id);
	}

	/**
	 * @param embossed
	 * @see com.yunfeng.aolin.service.EmbossedService#saveOrUpdate(com.yunfeng.aolin.entity.Embossed)
	 */
	@Override
	public void saveOrUpdate(Embossed embossed) {
		embossedDAO.save(embossed);
	}

	/**
	 * @param id
	 * @see com.yunfeng.aolin.service.EmbossedService#delete(java.lang.Long)
	 */
	@Override
	public void delete(Long id) {
		embossedDAO.delete(id);
	}

	@Override
	public List<Embossed> findAll() {
		// TODO Auto-generated method stub
		return embossedDAO.findAll();
	}

	/**
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.EmbossedService#findAll(com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<Embossed> findAll(Page page) {
		org.springframework.data.domain.Page<Embossed> springDataPage = embossedDAO
				.findAll(PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * @param page
	 * @param liaohao
	 * @return
	 * @see com.yunfeng.aolin.service.EmbossedService#findByLiaohao(com.ketayao.ketacustom.util.dwz.Page,
	 *      java.lang.String)
	 */
	@Override
	public List<Embossed> findByLiaohao(Page page, String liaohao) {
		org.springframework.data.domain.Page<Embossed> springDataPage = embossedDAO
				.findByLiaohaoContaining(liaohao,
						PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * 
	 * @param specification
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.EmbossedService#findByExample(org.springframework.data.jpa.domain.Specification,
	 *      com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<Embossed> findByExample(Specification<Embossed> specification,
			Page page) {
		org.springframework.data.domain.Page<Embossed> springDataPage = embossedDAO
				.findAll(specification, PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}
}
